package com.lagou.edu.api.impl;

import com.lagou.edu.api.AuthCodeServiceApi;
import com.lagou.edu.api.EmailServiceApi;
import com.lagou.edu.service.AuthCodeService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class AuthCodeServiceApiImpl implements AuthCodeServiceApi {
    @Autowired
    private AuthCodeService codeService;

    @Reference
    private EmailServiceApi emailServiceApi;

    @Override
    public String create(String email) {
        String code = codeService.generateCode(email);

        boolean resp = emailServiceApi.send(email, code);

        return resp ? "true" : "false";
    }

    @Override
    public String validate(String email, String code) {
        String checkResult = codeService.validate(email, code);

        return checkResult;
    }
}
